/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProxyServer.java
 *
 * Created on Jan 4, 2010, 12:51:42 PM
 */

package com.cloudminga.gui;

import java.awt.Dimension;
import java.awt.Toolkit;

/**
 *
 * @author USER
 */
public class ProxyServer extends javax.swing.JDialog {

    /** Creates new form ProxyServer */
    public ProxyServer(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        setTitle("Proxy Server");
           Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension SizeOfScreen = toolkit.getScreenSize();
        int x = ((SizeOfScreen.width - 418) / 2);
        int y = ((SizeOfScreen.height - 462) / 2);
        setLocation(x,y);/*to dispaly frame at the centre of the screen*/
      
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        proxyServerBtGroup = new javax.swing.ButtonGroup();
        proxyAuthenticationBtGroup = new javax.swing.ButtonGroup();
        notUseProxyRadiobt = new javax.swing.JRadioButton();
        useProxyRadiobt = new javax.swing.JRadioButton();
        proxyServerNameTextBox = new javax.swing.JTextField();
        defaultProxyRadiobt = new javax.swing.JRadioButton();
        autoDetectProxyRadiobt = new javax.swing.JRadioButton();
        autoProxyRadiobt = new javax.swing.JRadioButton();
        URLLable = new javax.swing.JLabel();
        URLtextBox = new javax.swing.JTextField();
        proxySettingsbt = new javax.swing.JButton();
        proxyAuthenticationPanel = new javax.swing.JPanel();
        notAuthenticateRadiobt = new javax.swing.JRadioButton();
        domainAuthenticateRadiobt = new javax.swing.JRadioButton();
        nameAndPassRadiobt = new javax.swing.JRadioButton();
        userNameLable = new javax.swing.JLabel();
        passwordLable = new javax.swing.JLabel();
        domainLable = new javax.swing.JLabel();
        userNameTextBox = new javax.swing.JTextField();
        passWordTextBox = new javax.swing.JTextField();
        domainTextBox = new javax.swing.JTextField();
        okProxyBt = new javax.swing.JButton();
        cancelProxyBt = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        proxyServerBtGroup.add(notUseProxyRadiobt);
        notUseProxyRadiobt.setSelected(true);
        notUseProxyRadiobt.setText("Do not use a proxy to connect to servers");
        notUseProxyRadiobt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                notUseProxyRadiobtActionPerformed(evt);
            }
        });

        proxyServerBtGroup.add(useProxyRadiobt);
        useProxyRadiobt.setText("use this proxy server:");
        useProxyRadiobt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useProxyRadiobtActionPerformed(evt);
            }
        });

        proxyServerNameTextBox.setEnabled(false);

        proxyServerBtGroup.add(defaultProxyRadiobt);
        defaultProxyRadiobt.setText("Use this computer's default proxy server");
        defaultProxyRadiobt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                defaultProxyRadiobtActionPerformed(evt);
            }
        });

        proxyServerBtGroup.add(autoDetectProxyRadiobt);
        autoDetectProxyRadiobt.setText("Automatic detect proxy settings");
        autoDetectProxyRadiobt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                autoDetectProxyRadiobtActionPerformed(evt);
            }
        });

        proxyServerBtGroup.add(autoProxyRadiobt);
        autoProxyRadiobt.setText("Use automatic configuration script:");
        autoProxyRadiobt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                autoProxyRadiobtActionPerformed(evt);
            }
        });

        URLLable.setText("URL:");

        URLtextBox.setEnabled(false);

        proxySettingsbt.setText("Import Windows Proxy Settings");

        proxyAuthenticationPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Proxy authentication"));

        proxyAuthenticationBtGroup.add(notAuthenticateRadiobt);
        notAuthenticateRadiobt.setSelected(true);
        notAuthenticateRadiobt.setText("My proxy server does not require authentication");
        notAuthenticateRadiobt.setEnabled(false);
        notAuthenticateRadiobt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                notAuthenticateRadiobtActionPerformed(evt);
            }
        });

        proxyAuthenticationBtGroup.add(domainAuthenticateRadiobt);
        domainAuthenticateRadiobt.setText("My proxy server authenticates my computer via the domain");
        domainAuthenticateRadiobt.setEnabled(false);
        domainAuthenticateRadiobt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                domainAuthenticateRadiobtActionPerformed(evt);
            }
        });

        proxyAuthenticationBtGroup.add(nameAndPassRadiobt);
        nameAndPassRadiobt.setText("My proxy requires a user name and password");
        nameAndPassRadiobt.setEnabled(false);
        nameAndPassRadiobt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nameAndPassRadiobtActionPerformed(evt);
            }
        });

        userNameLable.setText("User name:");

        passwordLable.setText("Password:");

        domainLable.setText("Domain:");

        userNameTextBox.setEnabled(false);

        passWordTextBox.setEnabled(false);

        domainTextBox.setEnabled(false);
        domainTextBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                domainTextBoxActionPerformed(evt);
            }
        });

        okProxyBt.setText("Ok");

        cancelProxyBt.setText("Cancel");
        cancelProxyBt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelProxyBtActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout proxyAuthenticationPanelLayout = new javax.swing.GroupLayout(proxyAuthenticationPanel);
        proxyAuthenticationPanel.setLayout(proxyAuthenticationPanelLayout);
        proxyAuthenticationPanelLayout.setHorizontalGroup(
            proxyAuthenticationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(proxyAuthenticationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(proxyAuthenticationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(nameAndPassRadiobt)
                    .addComponent(notAuthenticateRadiobt)
                    .addComponent(domainAuthenticateRadiobt)
                    .addGroup(proxyAuthenticationPanelLayout.createSequentialGroup()
                        .addComponent(userNameLable)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(userNameTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(proxyAuthenticationPanelLayout.createSequentialGroup()
                        .addGroup(proxyAuthenticationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(passwordLable)
                            .addComponent(domainLable))
                        .addGap(14, 14, 14)
                        .addGroup(proxyAuthenticationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(passWordTextBox, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
                            .addComponent(domainTextBox, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE))))
                .addContainerGap(27, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, proxyAuthenticationPanelLayout.createSequentialGroup()
                .addGap(96, 96, 96)
                .addComponent(okProxyBt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
                .addComponent(cancelProxyBt)
                .addGap(78, 78, 78))
        );
        proxyAuthenticationPanelLayout.setVerticalGroup(
            proxyAuthenticationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(proxyAuthenticationPanelLayout.createSequentialGroup()
                .addComponent(notAuthenticateRadiobt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(domainAuthenticateRadiobt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(nameAndPassRadiobt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(proxyAuthenticationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(userNameLable)
                    .addComponent(userNameTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(proxyAuthenticationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(passwordLable)
                    .addComponent(passWordTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(proxyAuthenticationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(domainLable)
                    .addComponent(domainTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(proxyAuthenticationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelProxyBt)
                    .addComponent(okProxyBt))
                .addContainerGap(11, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(proxyAuthenticationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(21, 21, 21)
                            .addComponent(proxyServerNameTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(notUseProxyRadiobt, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(useProxyRadiobt)
                        .addComponent(defaultProxyRadiobt)
                        .addComponent(autoDetectProxyRadiobt)
                        .addComponent(autoProxyRadiobt, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(14, 14, 14)
                            .addComponent(URLLable)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(URLtextBox)))
                    .addComponent(proxySettingsbt))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(notUseProxyRadiobt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(useProxyRadiobt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(proxyServerNameTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(defaultProxyRadiobt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(autoDetectProxyRadiobt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(autoProxyRadiobt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(URLtextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(URLLable))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(proxySettingsbt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(proxyAuthenticationPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        proxyAuthenticationPanel.getAccessibleContext().setAccessibleName("proxyAuthentication");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void domainTextBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_domainTextBoxActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_domainTextBoxActionPerformed

    private void useProxyRadiobtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useProxyRadiobtActionPerformed
        // TODO add your handling code here:
      
        notUseProxyRadiobt.setSelected(false);
        URLtextBox.setEnabled(false);
        useProxyRadiobt.setSelected(true);
        proxyServerNameTextBox.setEnabled(true);
        notAuthenticateRadiobt.setEnabled(true);
        domainAuthenticateRadiobt.setEnabled(true);
        nameAndPassRadiobt.setEnabled(true);
    }//GEN-LAST:event_useProxyRadiobtActionPerformed

    private void notUseProxyRadiobtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_notUseProxyRadiobtActionPerformed
        // TODO add your handling code here:
        if(notUseProxyRadiobt.isSelected()==true){
        useProxyRadiobt.setSelected(false);
        URLtextBox.setEnabled(false);
        proxyServerNameTextBox.setEnabled(false);
        notAuthenticateRadiobt.setEnabled(false);
        domainAuthenticateRadiobt.setEnabled(false);
        nameAndPassRadiobt.setEnabled(false);

        }

    }//GEN-LAST:event_notUseProxyRadiobtActionPerformed

    private void nameAndPassRadiobtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameAndPassRadiobtActionPerformed
        // TODO add your handling code here:
        userNameTextBox.setEnabled(true);
        passWordTextBox.setEnabled(true);
        domainTextBox.setEnabled(true);
    }//GEN-LAST:event_nameAndPassRadiobtActionPerformed

    private void domainAuthenticateRadiobtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_domainAuthenticateRadiobtActionPerformed
        // TODO add your handling code here:
         userNameTextBox.setEnabled(false);
         passWordTextBox.setEnabled(false);
         domainTextBox.setEnabled(false);
    }//GEN-LAST:event_domainAuthenticateRadiobtActionPerformed

    private void notAuthenticateRadiobtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_notAuthenticateRadiobtActionPerformed
        // TODO add your handling code here:
         userNameTextBox.setEnabled(false);
        passWordTextBox.setEnabled(false);
        domainTextBox.setEnabled(false);
    }//GEN-LAST:event_notAuthenticateRadiobtActionPerformed

    private void autoProxyRadiobtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoProxyRadiobtActionPerformed
        // TODO add your handling code here:
        if(autoProxyRadiobt.isSelected()==true){
            URLtextBox.setEnabled(true);
            proxyServerNameTextBox.setEnabled(false);
             notAuthenticateRadiobt.setEnabled(true);
        domainAuthenticateRadiobt.setEnabled(true);
        nameAndPassRadiobt.setEnabled(true);
        }
        else if(autoProxyRadiobt.isSelected()==false){
            URLtextBox.setEnabled(false);
        }

    }//GEN-LAST:event_autoProxyRadiobtActionPerformed

    private void defaultProxyRadiobtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultProxyRadiobtActionPerformed
        // TODO add your handling code here:
        URLtextBox.setEnabled(false);
        proxyServerNameTextBox.setEnabled(false);
         notAuthenticateRadiobt.setEnabled(true);
        domainAuthenticateRadiobt.setEnabled(true);
        nameAndPassRadiobt.setEnabled(true);
    }//GEN-LAST:event_defaultProxyRadiobtActionPerformed

    private void autoDetectProxyRadiobtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoDetectProxyRadiobtActionPerformed
        // TODO add your handling code here:
        URLtextBox.setEnabled(false);
        proxyServerNameTextBox.setEnabled(false);
         notAuthenticateRadiobt.setEnabled(true);
        domainAuthenticateRadiobt.setEnabled(true);
        nameAndPassRadiobt.setEnabled(true);
}//GEN-LAST:event_autoDetectProxyRadiobtActionPerformed

    private void cancelProxyBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelProxyBtActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_cancelProxyBtActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ProxyServer dialog = new ProxyServer(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel URLLable;
    private javax.swing.JTextField URLtextBox;
    private javax.swing.JRadioButton autoDetectProxyRadiobt;
    private javax.swing.JRadioButton autoProxyRadiobt;
    private javax.swing.JButton cancelProxyBt;
    private javax.swing.JRadioButton defaultProxyRadiobt;
    private javax.swing.JRadioButton domainAuthenticateRadiobt;
    private javax.swing.JLabel domainLable;
    private javax.swing.JTextField domainTextBox;
    private javax.swing.JRadioButton nameAndPassRadiobt;
    private javax.swing.JRadioButton notAuthenticateRadiobt;
    private javax.swing.JRadioButton notUseProxyRadiobt;
    private javax.swing.JButton okProxyBt;
    private javax.swing.JTextField passWordTextBox;
    private javax.swing.JLabel passwordLable;
    private javax.swing.ButtonGroup proxyAuthenticationBtGroup;
    private javax.swing.JPanel proxyAuthenticationPanel;
    private javax.swing.ButtonGroup proxyServerBtGroup;
    private javax.swing.JTextField proxyServerNameTextBox;
    private javax.swing.JButton proxySettingsbt;
    private javax.swing.JRadioButton useProxyRadiobt;
    private javax.swing.JLabel userNameLable;
    private javax.swing.JTextField userNameTextBox;
    // End of variables declaration//GEN-END:variables

}
